<?php

namespace app\admin\controller;

use app\common\model\Notice as NoticeModel;

class Notice extends Base
{
    public function __construct()
    {
        parent::__construct();
        $this->isLogin();
    }

	protected $ntype = [
		'1' => '首页公告',
	];

    /**
     * @route('notice/noticelist')
     * 公告列表
     */
    public function noticelist()
    {
		$get['pos'] = input('get.pos',1);
		$noticeModel = new NoticeModel();
        $notice = $noticeModel->get_list_page('*',$get,$this->limit);

        $page = $notice->render();

        $tvar = array(
            "title" => "公告列表",
            "time" => time(),
			"list" => $notice,
			'get' => $get,
        );
        $this->assign("data", $tvar);
        $this->assign('page', $page);
        return $this->fetch('notice/noticelist');
    }
	
    /**
     * @route('notice/boxnotice')
     * 编辑添加公告
     */
    public function boxnotice()
    {
		$noticeModel = new NoticeModel();
        if(input('post.form') == 'submit'){
            $param =input('post.');
            $data = [
                'notice_title' => $param['notice_title'],
            ];

			$rs = $noticeModel->edit($data,$param['notice_id']);
            if($rs === false){
                $this->error('操作失败');
            }
            $this->success('操作成功');
        }
        $id = input('get.notice_id/d',0);
        $notice = null;
        if($id != 0){
            $notice =$noticeModel->getOne(['notice_id'=>$id]);
        }
        $tvar = array(
            "title" => "添加公告",
            "time"  => time(),
            "data" => $notice,
            "id" => $id,
        );
//        var_dump($tvar);die;
        $this->assign("data", $tvar);
        return $this->fetch('notice/boxnotice');
    }

    /**
     * @route('notice/delnotice')
     * 删除公告
     */
    public function delnotice()
    {
        $id = input('post.notice_id');
		$noticeModel = new NoticeModel();
        $rs = $noticeModel->Del($id);
//        if($rs === false){
//            $this->error("删除失败");
//        }
        $this->success('删除成功 ');
    }

}